using System;
using System.Data;
using System.Configuration;
using System.Web;
using Dune.Business.Domain;
using Edge.Business.Domain.Application;
using Edge.Business.Managers;
using Edge.Business.Security;
using Edge.Common.ComponentModel;
using Edge.Common.Services;
using Edge.Business.Entities;

namespace Edge.DAL.Managers
{
    public class PersonManager<T, TH, TM> : IPersonManager<T>
        where T : UserEntity<int>
        where TM : IAbstractManager<T, int> 
        where TH : BaseObjectHolder<int, T, TM>

    {
        private const int DEFAULT_ID = 1;

        #region IPersonManager Members

        public T GetCurrent()
        {
            TH holder = Locator.GetService<IContextObjects>().Get<TH>();
            return (T)holder.Object;
        }

        public bool IsDefinedCurrent()
        {
            TH holder = Locator.GetService<IContextObjects>().Get<TH>();
            return !(holder == null || holder.Object == null);
        }

        public T GetDefault()
        {
            //return Locator.GetService<IEmployeeManager>().Load(DEFAULT_EMPLOYEE_ID);
            return null;
        }

        public T GetCurrentAuthor()
        {
            T user;
            if (Locator.GetService<IPersonManager<T>>().IsDefinedCurrent())
                user = Locator.GetService<IPersonManager<T>>().GetCurrent();
            else
                user = Locator.GetService<IPersonManager<T>>().GetDefault();
            return user;
        }

        #endregion
    }
}